<?php

include_once("common.php");

$db = get_database_connection();

function course_numbers()
{
	$db = get_database_connection();
	
	$acronym = mysql_real_escape_string($_GET['acronym']);
	
	$query = sprintf("SELECT number, id FROM courses WHERE acronym = '%s' ORDER BY number ASC;", $acronym);
	$result = mysql_query($query);
	if(!$result) 
	{
		mysql_free_result($result);
		echo '[ { value : "ERROR" } ]';
		return;
	}
	
	printf("[");
	
	while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	    printf("{ number: '%s', course_id: '%s' }, ", $row[0], $row[1]);
	}
	
	printf(" ]");
	
	return;
}


function course_object()
{
	$course_id = mysql_real_escape_string($_GET['course_id']);
	$course = get_course_array($course_id);
	echo json_encode($course);	
}


switch($_GET['task'])
{
	case 'course_numbers': course_numbers(); break;
	case 'course_object': course_object(); break;
	case 'get_classes_by_semester': echo gpp_classes_by_semester_json(); break;
	case 'perform_search': echo gpp_search_classes_json($_GET['search_major'], $_GET['search_terms']); break;
	case 'get_remaining_requirements': echo gpp_get_remaining_reqs(); break;
	case 'save_schedule': echo gpp_save_schedule_json($_GET['data']); break;
	case 'save_history': echo gpp_save_history_json($_GET['data']); break;
	case 'get_history': echo gpp_history_json(); break;
	case 'set_prereqs': echo gpp_set_prereqs($_GET['data']); break;
	
}

?>